Solution#359
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great work on the overall logic for handling different destination paths. I am requesting changes because the current implementation doesn't fully meet a key requirement: the app must support only moving files, but your code also moves directories. Please add a check to ensure the source is a file before proceeding; you can use fs.statSync(source).isFile() for this.
As a smaller improvement, you could also refactor the logic to have a single fs.renameSync call to make the code cleaner. Once the file-only check is in place, this will be ready!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| const [source, destination] = process.argv.slice(2); | ||
|
|
||
| try { | ||
| let finalDest = destination; |
There was a problem hiding this comment.
The requirements state that the app must support only moving files. The current implementation would also move a directory if it were provided as the source. It's a good practice to add a check here to verify that the source path is indeed a file before proceeding. You can use fs.statSync() for this, but remember to also handle cases where the source doesn't exist.
|
|
||
| finalDest = path.join(destination, path.basename(source)); | ||
|
|
||
| fs.renameSync(source, finalDest); |
There was a problem hiding this comment.
This fs.renameSync call is repeated on line 29. You could refactor the logic to first determine the correct finalDest based on all conditions (destination ending with /, or destination being an existing directory), and then have a single fs.renameSync call at the end of the try block. This would make the code cleaner and avoid repetition.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work addressing the feedback from the previous review! All functional requirements have been met, and the logic correctly handles moving files while rejecting directories. I am approving this submission.
I've left a couple of minor, non-blocking suggestions for you to consider. There's a small typo in an error message in src/app.js, and a small opportunity to refactor the destination path logic to make it a bit cleaner and avoid repetition. Feel free to look at these suggestions, but they are not required for this merge. Great job!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
|
|
||
| try { | ||
| if (!source || !destination) { | ||
| throw new Error('Invzlid arguments'); |
There was a problem hiding this comment.
There's a small typo here. It should be Invalid arguments.
| if (destination.endsWith('/')) { | ||
| if ( | ||
| !fs.existsSync(destination) || | ||
| !fs.statSync(destination).isDirectory() | ||
| ) { | ||
| throw new Error('Destination directory does not exist'); | ||
| } | ||
|
|
||
| finalDest = path.join(destination, path.basename(source)); | ||
| } else if ( | ||
| fs.existsSync(destination) && | ||
| fs.statSync(destination).isDirectory() | ||
| ) { | ||
| finalDest = path.join(destination, path.basename(source)); | ||
| } |
There was a problem hiding this comment.
Great job handling both cases for the destination directory (with and without a trailing slash). To make the code even cleaner, you could refactor this if/else if structure to avoid repeating the finalDest = path.join(...) line. You could use a variable to track if the destination is a directory, and then set finalDest once based on that variable.
No description provided.